/**
 * Created by zander on 2017/11/21.
 */

function saveEmail() {
    var eamil = $("#Addemail").val();
    var sessionStorage = window.sessionStorage;
    sessionStorage.setItem('myemail', eamil);
    $('#myEmail').modal('hide');
}

function jobStatus(id, btn) {
    $.ajax({
        type: "POST",
        url: "/intest/getjobStatus",
        data: {id: id},
        async: true,
        dataType: "json",
        success: function (ret) {
            if (ret.status == "0000") {
                $("#btnruner" + btn).removeAttr("disabled");
            }
        },

    });
}

function run1() {
    $("#btnruner1").button('loading').queue(function () {
        var sessionStorage = window.sessionStorage;
        var myemail = sessionStorage.getItem('myemail');
        var localStorage = window.localStorage;
        var name = localStorage.getItem('name');
        $.ajax({
            type: "POST",
            url: "/intest/buildjob",
            data: {jobid: 24, email: myemail, username: name},
            dataType: "json",
            success: function (ret) {
                if (ret.status == "0000") {
                    $("#btnruner1").attr("disabled", "disabled");
                }
            },

        });
        window.sessionStorage.clear();
    });
}
function run2() {
    $("#btnruner2").button('loading').queue(function () {
        var sessionStorage = window.sessionStorage;
        var myemail = sessionStorage.getItem('myemail');
        var localStorage = window.localStorage;
        var name = localStorage.getItem('name');
        $.ajax({
            type: "POST",
            url: "/intest/buildjob",
            data: {jobid: 14, email: myemail, username: name},
            dataType: "json",
            success: function (ret) {
                if (ret.status == "0000") {
                    $("#btnruner2").attr("disabled", "disabled");
                }
            },

        });
        window.sessionStorage.clear();
    });
}
function run3() {
    $("#btnruner3").button('loading').queue(function () {
        var sessionStorage = window.sessionStorage;
        var myemail = sessionStorage.getItem('myemail');
        var localStorage = window.localStorage;
        var name = localStorage.getItem('name');
        $.ajax({
            type: "POST",
            url: "/intest/buildjob",
            data: {jobid: 18, email: myemail, username: name},
            dataType: "json",
            success: function (ret) {
                if (ret.status == "0000") {
                    $("#btnruner3").attr("disabled", "disabled");
                }
            },

        });
        window.sessionStorage.clear();
    });
}

function run4() {
    $("#btnruner4").button('loading').queue(function () {
        var sessionStorage = window.sessionStorage;
        var myemail = sessionStorage.getItem('myemail');
        var localStorage = window.localStorage;
        var name = localStorage.getItem('name');
        $.ajax({
            type: "POST",
            url: "/intest/buildjob",
            data: {jobid: 17, email: myemail, username: name},
            dataType: "json",
            success: function (ret) {
                if (ret.status == "0000") {
                    $("#btnruner4").attr("disabled", "disabled");
                }
            },

        });
        window.sessionStorage.clear();
    });
}
function run5() {
    $("#btnruner5").button('loading').queue(function () {
        var sessionStorage = window.sessionStorage;
        var myemail = sessionStorage.getItem('myemail');
        var localStorage = window.localStorage;
        var name = localStorage.getItem('name');
        $.ajax({
            type: "POST",
            url: "/intest/buildjob",
            data: {jobid: 6, email: myemail, username: name},
            dataType: "json",
            success: function (ret) {
                if (ret.status == "0000") {
                    $("#btnruner5").attr("disabled", "disabled");
                }
            },

        });
        window.sessionStorage.clear();
    });
}
function run6() {
    $("#btnruner6").button('loading').queue(function () {
        var sessionStorage = window.sessionStorage;
        var myemail = sessionStorage.getItem('myemail');
        var localStorage = window.localStorage;
        var name = localStorage.getItem('name');
        $.ajax({
            type: "POST",
            url: "/intest/buildjob",
            data: {jobid: 33, email: myemail, username: name},
            dataType: "json",
            success: function (ret) {
                if (ret.status == "0000") {
                    $("#btnruner5").attr("disabled", "disabled");
                }
            },

        });
        window.sessionStorage.clear();
    });
}

function run7() {
    $("#btnruner7").button('loading').queue(function () {
        var sessionStorage = window.sessionStorage;
        var myemail = sessionStorage.getItem('myemail');
        var localStorage = window.localStorage;
        var name = localStorage.getItem('name');
        $.ajax({
            type: "POST",
            url: "/intest/buildjob",
            data: {jobid: 40, email: myemail, username: name},
            dataType: "json",
            success: function (ret) {
                if (ret.status == "0000") {
                    $("#btnruner7").attr("disabled", "disabled");
                }
            },

        });
        window.sessionStorage.clear();
    });
}

function sleep(numberMillis) {
    var now = new Date();
    var exitTime = now.getTime() + numberMillis;
    while (true) {
        now = new Date();
        if (now.getTime() > exitTime)
            return;
    }
}

function sessionClear() {
    window.sessionStorage.clear();
}

window.onload = sessionClear();
window.onload = jobStatus(24, 1);
window.onload = jobStatus(14, 2);
// window.onload = jobStatus(18,3);
// window.onload = jobStatus(17,4);
window.onload = jobStatus(6, 5);
window.onload = jobStatus(33, 6);
window.onload = jobStatus(40, 7);